<script setup>
import { computed, ref } from "vue";
const age = ref(18);
const nextAge = computed(() => {
  return +age.value + 1;
});
// 后年的年龄可以分为get,修改当前的值,set得到当前的值,去修改今年的值
const nextAge2 = computed({
  get() {
    return +age.value + 2;
  },
  set(value) {
    age.value = value - 2;
  },
});
</script>

<template>
  <div>我今年的年纪 <input type="text" v-model="age" /></div>
  <div>我明年的年龄 {{ nextAge }}</div>
  <div>我后年的年龄 <input type="text" v-model="nextAge2" /></div>
</template>

<style lang="scss" scoped></style>
